<?php

$dns = "mysql:dbname=test1;host=127.0.0.1";
$username = "root";
$password = "root";

$name=$_GET["username"];
$sex=$_GET["sex"]==0?"男":"女";
$age=$_GET["age"];

try {
    $pdo = new PDO($dns, $username, $password);
    echo "数据库连接成功...<br>";
    $sql = "INSERT into tb_user(name,age,sex) VALUES(?,?,?);";
    $stmt = $pdo->prepare($sql);
    $stmt->bindValue(1,$name);
    $stmt->bindValue(2,$age);
    $stmt->bindValue(3,$sex);
    $res = $stmt->execute();
    if($res>0)
        echo "<br>添加用户成功";
    else
        echo "<br>添加用户失败";

} catch (PDOException $e) {
    echo "数据库连接出错: " + $e->getMessage();
}